

//
function FermentationCalculator(tempScale, measScale) {
	this.temperatureScale = tempScale;
	this.measurementScale = measScale;
}


// TODO: Convert to accept alternative measurement scale
FermentationCalculator.prototype.calculateAlcoholByWeight = function (
	startingTemperature, startingSpecificGravity, 
	endingTemperature, endingSpecificGravity) {

	var correctedStartingSG;
	var correctedEndingSG;
	var startTempF;
	var endTempF;
	
	if(this.temperatureScale === TemperatureScale.FAHRENHEIT) {
		startTempF = startTemp;
		endTempF = endTemp;
	} else {
		startTempF = convertToFahrenheit(startTemp);
		endTempF = convertToFahrenheit(endTemp);
	}
	
	correctedStartingSG = correctSpecificGravity(startSG, startTempF);
	correctedEndingSG = correctSpecificGravity(endSG, endTempF);
	
	return (correctedStartingSG - correctedEndingSG) * 105;
}


// TODO: Convert to accept alternative measurement scale
FermentationCalculator.prototype.calculateAlcoholByVolume = function (
	startingTemperature, startingSpecificGravity, 
	endingTemperature, endingSpecificGravity) {

	var correctedStartingSG;
	var correctedEndingSG;
	var startTempF;
	var endTempF;
	
	if(this.temperatureScale === TemperatureScale.FAHRENHEIT) {
		startTempF = startTemp;
		endTempF = endTemp;
	} else {
		startTempF = convertToFahrenheit(startTemp);
		endTempF = convertToFahrenheit(endTemp);
	}	
	
	correctedStartingSG = correctSpecificGravity(startSG, startTempF);
	correctedEndingSG = correctSpecificGravity(endSG, endTempF);
	
	return ((correctedStartingSG - correctedEndingSG) * 105) * 1.25;

}


//
FermentationCalculator.prototype.correctSpecificGravity = function(
	originalMeasurement, temperature) {
	
	var temperatureToUse;
		
	if(this.temperatureScale === TemperatureScale.FAHRENHEIT) {
		temperatureToUse = temperature;
	} else {
		temperatureToUse = convertCelsiusToFahrenheit(temperature);
	}
	
	// Assumes accurate reading at 60 degrees Fahrenheit
	var correctionPerDegreeF = 0.00025;
	var correctionValue;
	var temperatureDifference;
	
	temperatureDifference = temperatureToUse - 60.0;
	correctionValue =  temperatureDifference * correctionPerDegreeF;	
	
	return originalSpecificGravity + correctionValue;
}



